﻿var count = 0;
jQuery(document).ready(function() {
    var btn = jQuery("#ctl00_ContentPlaceHolder1_Button3");
    var len = jQuery("#ctl00_ContentPlaceHolder1_GridView2 :checkbox").length;
    btn.attr("disabled", "disabled");
    if (len > 0) {
        jQuery("#ctl00_ContentPlaceHolder1_GridView2 :checkbox").attr("checked", false);
        jQuery("#ctl00_ContentPlaceHolder1_GridView2 :checkbox").each(function() {
            jQuery(this).click(function() {
                if (jQuery(this).attr("checked")) {
                    count++;
                    if (count == len) {
                        jQuery("#ctl00_ContentPlaceHolder1_CheckBox2").attr("checked", true);
                    }
                    btn.removeAttr("disabled");
                }
                else {
                    jQuery("#ctl00_ContentPlaceHolder1_CheckBox2").attr("checked", false);
                    if (count > 0) {
                        count--;
                    }
                    if (count == 0) {
                        btn.attr("disabled", "disabled");
                    }
                }
            });
        });
        jQuery("#ctl00_ContentPlaceHolder1_CheckBox2").click(function() {
            if (jQuery(this).attr("checked")) {
                jQuery("#ctl00_ContentPlaceHolder1_GridView2 :checkbox").attr("checked", true);
                count = len;
                btn.removeAttr("disabled");
            }
            else {
                jQuery("#ctl00_ContentPlaceHolder1_GridView2 :checkbox").attr("checked", false);
                count = 0;
                btn.attr("disabled", "disabled");
            }
        });
    }
    else {
        jQuery("#makeall").css("display", "none");
    }
});
